<?php include "./pc/view/header.inc.htm"; ?>

<div class="container">
    <div class="content">
        <div class="content-header">
            <div class="tw-header-inner">
                <h2>修改密码</h2>
            </div>
        </div>
        <div class="content-body">
            <div class="reply-form">
                <div class="reply-inner">
                    <div class="topic-content clearfix">
                        <div class="topic-user">
                            <img src="<?php echo $user['avatar_url']; ?>" class="avatar" id="avatar_img" alt="<?php echo $user['username']; ?>" title="<?php echo $user['username']; ?>">
                            <strong><?php echo $user['username']; ?></strong>
                            <small>我就是我，不一样的烟火~</small>
                        </div>
                    </div>
                </div>
            </div>
            <div class="content-inner">
                <div class="signin-wrapper user-profile">
                <form class="signin" action="my-password.htm" method="post" id="my_password_form">
                    <fieldset>
                        <div class="field">
                            旧的密码：
                            <input type="password" name="password" placeholder="旧的密码">
                        </div>
                        <div class="field">
                            新的密码：
                            <input type="password" name="newpassword" placeholder="新的密码">
                        </div>
                        <div class="field">
                            重复密码：
                            <input type="password" name="newpassword2" placeholder="重复密码">
                        </div>
                    </fieldset>
                    <div class="button">
                        <button type="submit" class="primary-btn" loading-text="正在登录...">
                            保存
                        </button>
                    </div>
                </form>
                </div>
            </div>
        </div>
    </div>
    <div class="dashboard">

        <?php include "./pc/view/my_header.inc.htm"; ?>

        <?php include "./pc/view/copyright.htm"; ?>

    </div>
    <div class="clear"></div>
</div>

<?php include "./pc/view/my_footer.inc.htm"; ?>

<script>

var jform = $('#my_password_form');
var jpassword = jform.find('input[name="password"]');
var jnewpassword = jform.find('input[name="newpassword"]');
var jnewpassword2 = jform.find('input[name="newpassword2"]');
var jsubmit = jform.find('button[type="submit"]');
jform.off('submit').on('submit', function() {
    if(!jpassword.val()) {
        jpassword.popover('请输入旧密码').focus();
        return false;
    } else if(!jnewpassword.val()) {
        jnewpassword.popover('请输入新密码').focus();
        return false;
    } else if(jnewpassword.val() != jnewpassword2.val()) {
        jnewpassword2.popover('两次输入的密码不一致。').focus();
        return false;
    }
    var postdata = "password="+$.md5(jpassword.val())+"&newpassword="+$.md5(jnewpassword.val());
    jsubmit.button('loading');
    $.xpost(jform.attr('action'), postdata, function(code, message) {
        if(code == 0) {
            jsubmit.text(message);
            setTimeout(function() {jsubmit.button('reset');}, 2000);
            return;
        } else  if(code == 1) {
            jpassword.popover(message).focus();
        } else  if(code == 2) {
            jnewpassword.popover(message).focus();
        } else  if(code == 3) {
            jnewpassword2.popover(message).focus();
        } else {
            $.alert(message);
        }
        jsubmit.button('reset');
    });
    return false;
});

$('#my_profile_menu').find('a').eq(1).class_active();

</script>